import {
  EditableCheckbox,
  EditableDate,
  EditableInput,
  EditableModal,
  EditableNumber,
  EditableRadio,
  EditableSelect,
  EditableSwitch,
} from './Widgets';

import type { AnyObject, EditType } from '../../type';
import type { EditableCell } from './Widgets/type';

export interface Props {
  editType?: EditType;
}
type Config = {
  [key in EditType]?: (p: AnyObject & EditableCell) => React.JSX.Element;
};
function getEditableTableCellComponent(props: Props) {
  const { editType = 'string' } = props;
  const config: Config = {
    string: EditableInput,
    input: EditableInput,
    number: EditableNumber,
    select: EditableSelect,
    switch: EditableSwitch,
    radio: EditableRadio,
    checkbox: EditableCheckbox,
    date: EditableDate,
    modal: EditableModal,
  };
  return config[editType];
}
export default getEditableTableCellComponent;
